﻿namespace Catel.Articles._08___WP7_Camera.Data
{
    using System;
    using System.Windows.Controls;
    using Microsoft.Phone.Controls;

    /// <summary>
    /// Flick movements, easy to emulate flick gestures for testing purposes.
    /// </summary>
    public enum FlickMovement
    {
        /// <summary>
        /// Left to right.
        /// </summary>
        LeftToRight,

        /// <summary>
        /// Right to left.
        /// </summary>
        RightToLeft
    }

    /// <summary>
    /// Custom implementation for flick data because it's impossible to instantiate 
    /// the <see cref="FlickGestureEventArgs"/> class.
    /// </summary>
    public class FlickData
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FlickData"/> class.
        /// </summary>
        /// <param name="eventArgs">The <see cref="Microsoft.Phone.Controls.FlickGestureEventArgs"/> instance containing the event data.</param>
        public FlickData(FlickGestureEventArgs eventArgs)
            : this(eventArgs.Angle, eventArgs.Direction, eventArgs.HorizontalVelocity, eventArgs.VerticalVelocity) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="FlickData"/> class.
        /// </summary>
        /// <param name="angle">The angle.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="horizontalVelocity">The horizontal velocity.</param>
        /// <param name="verticalVelocity">The vertical velocity.</param>
        public FlickData(double angle, Orientation direction, double horizontalVelocity, double verticalVelocity)
        {
            Angle = angle;
            Direction = direction;
            HorizontalVelocity = horizontalVelocity;
            VerticalVelocity = verticalVelocity;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FlickData"/> class.
        /// </summary>
        /// <param name="movement">The movement.</param>
        /// <remarks>
        /// This method should only be used for test purposes.
        /// </remarks>
        public FlickData(FlickMovement movement)
        {
            Angle = 0;
            Direction = Orientation.Horizontal;
            VerticalVelocity = 0;

            switch (movement)
            {
                case FlickMovement.LeftToRight:
                    HorizontalVelocity = 15;
                    break;

                case FlickMovement.RightToLeft:
                    HorizontalVelocity = -15;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("movement");
            }
        }

        /// <summary>
        /// Gets or sets the angle.
        /// </summary>
        /// <value>The angle.</value>
        public double Angle { get; set; }

        /// <summary>
        /// Gets or sets the direction.
        /// </summary>
        /// <value>The direction.</value>
        public Orientation Direction { get; set; }

        /// <summary>
        /// Gets or sets the horizontal velocity.
        /// </summary>
        /// <value>The horizontal velocity.</value>
        public double HorizontalVelocity { get; set; }

        /// <summary>
        /// Gets or sets the vertical velocity.
        /// </summary>
        /// <value>The vertical velocity.</value>
        public double VerticalVelocity { get; set; }
    }
}
